package entities;

import backbone.IPaintable;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;



/**
 * Parent class that defines point objects.
 * @author Paul
 * @author Lance
 */
public abstract class PointObject implements IPaintable {

    private static final int POINT_SIZE = 16;
    private Point2D myCenter;
    private Dimension mySize;
    private int myID;

    /**
     * @param id object id
     * @param x x location
     * @param y y location
     */
    public PointObject (int id, double x, double y) {
        myID = id;
        setCenter(x, y);
        mySize = new Dimension(POINT_SIZE, POINT_SIZE);
    }

    /**
     * @param id object ID
     * @return true if same object ID
     *
     */
    public boolean match(int id) {
        return myID == id;
    }

    /**
     * @return center of point
     */
    public Point2D getCenter() {
        return myCenter;
    }


    /**
     * @param x x location
     * @param y y location
     */
    public void setCenter(double x, double y) {
        myCenter = new Point2D.Double(x, y);
    }


    /**
     * Returns shape's left-most coordinate.
     */
    public int getLeft() {
        return (int) (getCenter().getX() - getSize().width / 2);
    }

    /**
     * Returns shape's top-most coordinate.
     */
    public int getTop() {
        return (int) (getCenter().getY() - getSize().height / 2);
    }

    /**
     * Returns shape's right-most coordinate.
     */
    public int getRight() {
        return (int) (getCenter().getX() + getSize().width / 2);
    }

    /**
     * Reports shape's bottom-most coordinate.
     *
     * @return bottom-most coordinate
     */
    public int getBottom() {
        return (int) (getCenter().getY() + getSize().height / 2);
    }

    /**
     * Returns shape's size.
     */
    public Dimension getSize() {
        return mySize;
    }

    /**
     * @param p point object
     * @return angle between two point objects
     */
    public double getAngleBetween(PointObject p) {
        double x = p.getCenter().getX();
        double y = p.getCenter().getY();
        return Math.toDegrees(Math.atan((y - getCenter().getY())
                  / (x - getCenter().getX())));
    }

    /**
     * @param p point object
     * @return distance between the two point objects
     */
    public double getDistance(PointObject p) {
        double x = p.getCenter().getX();
        double y = p.getCenter().getY();
        return Math.sqrt(Math.pow(getCenter().getY() - y, 2)
                + Math.pow(getCenter().getX() - x, 2));
    }
    
    public int getID () {
        return myID;
    }

    /**
     * @param pen Graphics2D
     */
    public abstract void paint (Graphics2D pen);

}
